<?php
defined('SYSPATH') or die('No direct script access.');


class Controller_Qrcode extends Controller{

    public function action_index()
    {
        require_once Kohana::find_file("vendor/wechat",'unit/phpqrcode/phpqrcode');
        require_once Kohana::find_file("vendor/wechat","lib/WxPay.Api");
        require_once Kohana::find_file("vendor/wechat","unit/WxPay.NativePay");
        require_once Kohana::find_file("vendor/wechat","unit/log");
        if(isset($_GET["data"])&&isset($_GET["order_no"])&&isset($_GET["id"]))
        {
            $price=$_GET["data"];
            $no=$_GET["order_no"];
            $id=$_GET["id"];
        }
        // $notify = new NativePay();
        // $input = new WxPayUnifiedOrder();
        // $input->SetBody("神码浮云插件支付平台");
        // $input->SetAttach($id);
        // $input->SetOut_trade_no($no);
        // $input->SetTotal_fee($price*100);
        // $input->SetTime_start(date("YmdHis"));
        // $input->SetTime_expire(date("YmdHis", time() + 600));
        // $input->SetGoods_tag("神码浮云插件支付平台");
        // $input->SetNotify_url(URL::site("notify/index"));
        // $input->SetTrade_type("NATIVE");
        // $input->SetProduct_id($id);
        // $input->SetSpbill_create_ip("127.0.0.1");
        // $result = $notify->GetPayUrl($input);
        // $url = $result["code_url"];
        // $url = urldecode($url);
        // QRcode::png($url);
        // unset($_GET["data"]);
        // unset($_GET["order_no"]);
        // unset($_GET["id"]);

        require_once Kohana::find_file("vendor/kdt","KdtApiClient");

            $appId = 'c27bdd1e37cd8300fb';
            $appSecret = '3e7d8db9463b1e2fd92083418677c638';
            $client = new KdtApiClient($appId, $appSecret);


            $method = 'kdt.pay.qrcode.createQrCode';
            $params = [
                'qr_name' =>"water",

                'qr_price' => $price*100,
                'qr_type' => 'QR_TYPE_DYNAMIC',
            ];


            $test=$client->post($method, $params);
            header('Content-type: image/jpg');
            echo "<img src='".$test['response']['qr_code']."'>";

    }

}
?>
